<?php
$this->Paginator->options(array('url' => array('ext' => false, '?' => $this->request->query)));
?>
<div id="section" class="ui-tabs ui-widget ui-widget-content">
    <ul class="section-nav ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-top control-icon">
        <li class="ui-state-default ui-tabs-selected ui-state-active ui-corner-top">
            <a href="#"><span class="ui-icon icon-list"></span><?php echo __d('system', 'General'); ?></a>
        </li>
        <li class="ui-state-default ui-corner-top">
            <a href="#"><span class="ui-icon icon-list"></span><?php echo __d('system', 'Add demo'); ?></a>
        </li>
    </ul>
    <div id="section-1" class="section">
        <?php
        echo $this->element('Block' . DS . 'toolbar');
        ?>
        <!-- Table -->
        <div class="table-wrapper">
            <?php echo $this->Form->create('Filter', array('url' => '/' . $this->request->url, 'type' => 'get')); ?>
            <div class="table-toolbar clearfix">
                <div class="input table-length">
                    <?php
                    echo __d('system', 'Show %s entries', $this->Form->input('limit', array('id' => 'filter-limit', 'options' => array(20 => 20, 50 => 50, 100 => 100), 'div' => false, 'label' => false)));
                    ?>
                </div>
                <div class="table-filter">
                    <div class="input ui-corner-all">
                        <?php
                        echo $this->Form->input('q', array('id' => 'filter-keyword', 'size' => 30, 'div' => false, 'label' => false));
                        ?>
                        <span class="go">
                            <input id="filter-submit" value="go" type="submit" />
                        </span>
                    </div>
                    <?php if (!empty($_filterQueries)) : ?>
                        <div class="toggle">
                            <?php
                            $_url = '/' . $this->request->url;
                            $_requestQueries = array_diff_key($this->request->query, array_flip($_filterQueries));
                            if ($_requestQueries) {
                                $_url .= '?' . http_build_query($_requestQueries);
                            }
                            echo $this->Html->link('Reset', $_url, array('id' => 'filter-reset'));
                            ?>
                        </div>
                    <?php endif; ?>
                    <div class="toggle">
                        <input value="Filter options" type="checkbox" id="filter-toggle" />
                        <label for="filter-toggle">Options</label>
                    </div>
                </div>
            </div>
            <div id="filter-options" style="display:none" class="filter-options panel clearfix">
                <fieldset>
                    <div class="fieldset clearfix">
                        <h3 class="legend"><?php echo __d('system', 'Filter options'); ?></h3>
                        <div class="column">
                            <?php
                            $_filterFields = array(
                                'id' => __d('system', 'Id'),
                                'username' => __d('system', 'Username'),
                                'fullname' => __d('system', 'Fullname'),
                                'password' => __d('system', 'Password'),
                                'introduct' => __d('system', 'Introduct'),
                                'fulltext' => __d('system', 'Fulltext'),
                                'gender' => __d('system', 'Gender'),
                                'birthday' => __d('system', 'Birthday'),
                                'email' => __d('system', 'Email'),
                                'phone' => __d('system', 'Phone'),
                                'enabled' => __d('system', 'Enabled'),
                                'role_id' => __d('system', 'Role'),
                                'created' => __d('system', 'Created'),
                                'updated' => __d('system', 'Updated'),
                                'lft' => __d('system', 'Lft'),
                                'rght' => __d('system', 'Rght'),
                            );
                            echo $this->Form->input('d', array('label' => __d('system', 'Fields display'), 'multiple' => 'checkbox', 'hiddenField' => false, 'options' => $_filterFields));
                            ?>
                        </div>
                        <div class="column">

                            <?php
                            unset($_filterFields['gender'], $_filterFields['enabled'], $_filterFields['role_id']);
                            echo $this->Form->input('f', array('label' => __d('system', 'Fields filter by keyword'), 'multiple' => 'checkbox', 'hiddenField' => false, 'options' => $_filterFields));
                            ?>
                        </div>
                        <div class="clear"></div>

                        <div class="column">
                            <?php
                            echo $this->Form->input('_role_id', array('label' => __d('system', 'Role'), 'empty' => __d('system', '-- Any --'), 'options' => $roles));
                            ?>
                        </div>

                        <div class="column">
                            <?php
                            echo $this->Form->input('_gender', array('label' => __d('system', 'Gender'), 'empty' => __d('system', '-- Any --'), 'options' => array(__d('system', 'No'), __d('system', 'Yes'))));
                            ?>
                        </div>

                        <div class="column">
                            <?php
                            echo $this->Form->input('_enabled', array('label' => __d('system', 'Enabled'), 'empty' => __d('system', '-- Any --'), 'options' => array(__d('system', 'No'), __d('system', 'Yes'))));
                            ?>
                        </div>

                    </div>
                    <div class="ui-helper-hidden">
                        <?php
                        $_hiddenQueries = array_flip(array_merge($_filterQueries, array('sort', 'direction', 'page'), array(
                                    'gender',
                                    'enabled',
                                    'role_id'
                                )));
                        foreach ($this->request->query as $key => $value) {
                            if (isset($_hiddenQueries[$key])) {
                                continue;
                            }
                            echo $this->Form->hidden($key, array('value' => $value));
                        }
                        ?>
                    </div>
                </fieldset>
            </div>
            <?php echo $this->Form->end(); ?>
            <?php echo $this->Form->create('Paginate', array('id' => 'paginate', 'url' => $this->request->here(false), 'type' => 'post', 'inputDefaults' => array('label' => false))); ?>
            <div id="paginate-place">
                <?php if (!empty($_crumbs)): ?>
                    <div class="table-breadcrumb table-toolbar clearfix">
                        <?php
                        $this->Html->addCrumb(__d('system', 'Users'), array(
                            'ext' => false,
                            '?' => array_diff_key($this->request->query, array('_parent_id' => ''))
                        ));
                        $_endcrumb = array_pop($_crumbs);
                        foreach ($_crumbs as $_crumb) {
                            $this->Html->addCrumb($_crumb['User'][$_modelMaps['User']], array(
                                'ext' => false,
                                '?' => array_merge($this->request->query, array('_parent_id' => $_crumb['User']['id']))));
                        }
                        $this->Html->addCrumb($this->Html->tag('a', $_endcrumb['User'][$_modelMaps['User']]));
                        echo $this->Html->getCrumbs();
                        ?>
                    </div>
                <?php endif; ?>
                <?php if (!empty($_filterQueries)) : ?>
                    <div id="message-place">
                        <?php
                        echo $this->Layout->flash(__d('system', 'To reset this the filter please click button reset on the filter bar'), array(
                            'title' => __d('system', 'Filter results') . ':',
                            'type' => 'info'));
                        ?>
                    </div>
                <?php endif; ?>
                <div class="table-scroll">
                    <div class="table-content">
                        <table>
                            <thead>
                                <tr>
                                    <th>
                                        <span class="table-head">
                                            <span class="ui-icon ui-icon-flag"></span>
                                            <?php echo __d('system', 'No.'); ?>
                                        </span>
                                    </th>
                                    <th>
                                        <span class="table-head">
                                            <span class="ui-icon ui-icon-bookmark"></span>
                                            <input class="table-toggle" value="paginate-no" type="checkbox" title="<?php echo __d('system', 'Check all.'); ?>" />
                                        </span>
                                    </th>
                                    <?php if (isset($_displayFields['id'])): ?>
                                        <th>
                                            <span class="table-head">
                                                <?php echo $this->Paginator->sort('id', __d('system', 'Id')); ?>
                                            </span>
                                        </th>
                                    <?php endif; ?>
                                    <?php if (isset($_displayFields['username'])): ?>
                                        <th>
                                            <span class="table-head">
                                                <?php echo $this->Paginator->sort('username', __d('system', 'Username')); ?>
                                            </span>
                                        </th>
                                    <?php endif; ?>
                                    <?php if (isset($_displayFields['fullname'])): ?>
                                        <th>
                                            <span class="table-head">
                                                <?php echo $this->Paginator->sort('fullname', __d('system', 'Fullname')); ?>
                                            </span>
                                        </th>
                                    <?php endif; ?>
                                    <?php if (isset($_displayFields['password'])): ?>
                                        <th>
                                            <span class="table-head">
                                                <?php echo $this->Paginator->sort('password', __d('system', 'Password')); ?>
                                            </span>
                                        </th>
                                    <?php endif; ?>
                                    <?php if (isset($_displayFields['introduct'])): ?>
                                        <th>
                                            <span class="table-head">
                                                <?php echo $this->Paginator->sort('introduct', __d('system', 'Introduct')); ?>
                                            </span>
                                        </th>
                                    <?php endif; ?>
                                    <?php if (isset($_displayFields['fulltext'])): ?>
                                        <th>
                                            <span class="table-head">
                                                <?php echo $this->Paginator->sort('fulltext', __d('system', 'Fulltext')); ?>
                                            </span>
                                        </th>
                                    <?php endif; ?>
                                    <?php if (isset($_displayFields['gender'])): ?>
                                        <th>
                                            <span class="table-head">
                                                <?php echo $this->Paginator->sort('gender', __d('system', 'Gender')); ?>
                                            </span>
                                        </th>
                                    <?php endif; ?>
                                    <?php if (isset($_displayFields['birthday'])): ?>
                                        <th>
                                            <span class="table-head">
                                                <?php echo $this->Paginator->sort('birthday', __d('system', 'Birthday')); ?>
                                            </span>
                                        </th>
                                    <?php endif; ?>
                                    <?php if (isset($_displayFields['email'])): ?>
                                        <th>
                                            <span class="table-head">
                                                <?php echo $this->Paginator->sort('email', __d('system', 'Email')); ?>
                                            </span>
                                        </th>
                                    <?php endif; ?>
                                    <?php if (isset($_displayFields['phone'])): ?>
                                        <th>
                                            <span class="table-head">
                                                <?php echo $this->Paginator->sort('phone', __d('system', 'Phone')); ?>
                                            </span>
                                        </th>
                                    <?php endif; ?>
                                    <?php if (isset($_displayFields['enabled'])): ?>
                                        <th>
                                            <span class="table-head">
                                                <?php echo $this->Paginator->sort('enabled', __d('system', 'Enabled')); ?>
                                            </span>
                                        </th>
                                    <?php endif; ?>
                                    <?php if (isset($_displayFields['role_id'])): ?>
                                        <th>
                                            <span class="table-head">
                                                <?php echo $this->Paginator->sort('role_id', __d('system', 'Role')); ?>
                                            </span>
                                        </th>
                                    <?php endif; ?>
                                    <?php if (isset($_displayFields['created'])): ?>
                                        <th>
                                            <span class="table-head">
                                                <?php echo $this->Paginator->sort('created', __d('system', 'Created')); ?>
                                            </span>
                                        </th>
                                    <?php endif; ?>
                                    <?php if (isset($_displayFields['updated'])): ?>
                                        <th>
                                            <span class="table-head">
                                                <?php echo $this->Paginator->sort('updated', __d('system', 'Updated')); ?>
                                            </span>
                                        </th>
                                    <?php endif; ?>
                                    <?php if (isset($_displayFields['lft'])): ?>
                                        <th>
                                            <span class="table-head">
                                                <?php echo $this->Paginator->sort('lft', __d('system', 'Lft')); ?>
                                            </span>
                                        </th>
                                    <?php endif; ?>
                                    <?php if (isset($_displayFields['rght'])): ?>
                                        <th>
                                            <span class="table-head">
                                                <?php echo $this->Paginator->sort('rght', __d('system', 'Rght')); ?>
                                            </span>
                                        </th>
                                    <?php endif; ?>
                                    <?php if (isset($_translateMaps)): ?>
                                        <th>    
                                            <span class="table-head">
                                                <span class="ui-icon ui-icon-gear"></span>
                                                Translate                                                
                                            </span>
                                        </th>
                                    <?php endif; ?>
                                    <th>
                                        <span class="table-head">
                                            <span class="ui-icon ui-icon-gear"></span>
                                            <?php echo __d('system', 'Action'); ?>
                                        </span>
                                    </th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                $_row = 1;
                                $defaultLanguage = Router::defaultLanguage();
                                $_queries = array('continue' => $this->request->here(false));
                                ?>
                                <?php foreach ($users as $user) : ?>
                                    <tr class="table-row <?php echo $_row % 2 == 0 ? 'even' : 'odd'; ?>"> 
                                        <td class="table-col table-no">
                                            <?php echo $_row; ?>
                                        </td>
                                        <td class="table-col table-id">
                                            <?php echo $this->Form->input('id.', array('value' => $user['User']['id'], 'class' => 'paginate-no', 'type' => 'checkbox', 'hiddenField' => false, 'id' => false)); ?>
                                        </td>
                                        <?php if (isset($_displayFields['id'])): ?>
                                            <td class="table-col table-integer">
                                                <?php echo $user['User']['id']; ?>
                                            </td>
                                        <?php endif; ?>
                                        <?php if (isset($_displayFields['username'])): ?>
                                            <td class="table-col table-string">
                                                <?php echo String::truncate(strip_tags($user['User']['username'])); ?>
                                            </td>
                                        <?php endif; ?>
                                        <?php if (isset($_displayFields['fullname'])): ?>
                                            <td class="table-col table-string">
                                                <?php echo String::truncate(strip_tags($user['User']['fullname'])); ?>
                                            </td>
                                        <?php endif; ?>
                                        <?php if (isset($_displayFields['password'])): ?>
                                            <td class="table-col table-string">
                                                <?php echo String::truncate(strip_tags($user['User']['password'])); ?>
                                            </td>
                                        <?php endif; ?>
                                        <?php if (isset($_displayFields['introduct'])): ?>
                                            <td class="table-col table-string">
                                                <?php echo String::truncate(strip_tags($user['User']['introduct'])); ?>
                                            </td>
                                        <?php endif; ?>
                                        <?php if (isset($_displayFields['fulltext'])): ?>
                                            <td class="table-col table-text">
                                                <?php echo String::truncate(strip_tags($user['User']['fulltext'])); ?>
                                            </td>
                                        <?php endif; ?>
                                        <?php if (isset($_displayFields['gender'])): ?>
                                            <td class="table-col table-boolean">
                                                <?php echo $this->Form->checkbox('gender', array('disabled' => true, 'hiddenField' => false, 'name' => '', 'id' => false, 'checked' => (bool) $user['User']['gender'])); ?>
                                            </td>
                                        <?php endif; ?>
                                        <?php if (isset($_displayFields['birthday'])): ?>
                                            <td class="table-col table-date">
                                                <?php echo $this->Time->date($user['User']['birthday'], 'short'); ?>
                                            </td>
                                        <?php endif; ?>
                                        <?php if (isset($_displayFields['email'])): ?>
                                            <td class="table-col table-string">
                                                <?php echo String::truncate(strip_tags($user['User']['email'])); ?>
                                            </td>
                                        <?php endif; ?>
                                        <?php if (isset($_displayFields['phone'])): ?>
                                            <td class="table-col table-string">
                                                <?php echo String::truncate(strip_tags($user['User']['phone'])); ?>
                                            </td>
                                        <?php endif; ?>
                                        <?php if (isset($_displayFields['enabled'])): ?>
                                            <td class="table-col table-boolean">
                                                <?php echo $this->Form->checkbox('enabled', array('disabled' => true, 'hiddenField' => false, 'name' => '', 'id' => false, 'checked' => (bool) $user['User']['enabled'])); ?>
                                            </td>
                                        <?php endif; ?>
                                        <?php if (isset($_displayFields['role_id'])): ?>
                                            <td class="table-col table-string">
                                                <?php echo $user['Role'][$_modelMaps['Role']]; ?>
                                            </td>
                                        <?php endif; ?>
                                        <?php if (isset($_displayFields['created'])): ?>
                                            <td class="table-col table-datetime">
                                                <?php echo $this->Time->datetime($user['User']['created'], 'short'); ?>
                                            </td>
                                        <?php endif; ?>
                                        <?php if (isset($_displayFields['updated'])): ?>
                                            <td class="table-col table-datetime">
                                                <?php echo $this->Time->datetime($user['User']['updated'], 'short'); ?>
                                            </td>
                                        <?php endif; ?>
                                        <?php if (isset($_displayFields['lft'])): ?>
                                            <td class="table-col table-integer">
                                                <?php echo $user['User']['lft']; ?>
                                            </td>
                                        <?php endif; ?>
                                        <?php if (isset($_displayFields['rght'])): ?>
                                            <td class="table-col table-integer">
                                                <?php echo $user['User']['rght']; ?>
                                            </td>
                                        <?php endif; ?>
                                        <?php if (isset($_translateMaps)): ?>
                                            <td class="table-col">
                                                <div class="table-translate">
                                                    <?php
                                                    foreach (Configure::read('Languages') as $_language) {
                                                        if ($_language['code'] === $defaultLanguage) {
                                                            continue;
                                                        }
                                                        echo $this->Html->link($this->Html->image('flag/' . $_language['code'] . '.png'), array('action' => 'translate', $user['User']['id'], $_language['code'], '?' => $_queries), array(
                                                            'class' => isset($_translateMaps[$user['User']['id']][$_language['locale']]) ? '' : 'ui-state-disabled', 'escape' => false, 'title' => $_language['name']));
                                                    }
                                                    ?>
                                                </div>
                                            </td>
                                        <?php endif; ?>
                                        <td class="table-col">
                                            <div class="table-actions">
                                                <?php echo $this->Html->link('Edit', array('action' => 'edit', $user['User']['id'], '?' => $_queries), array('title' => __d('system', 'Edit this item'), 'class' => 'ui-icon ui-icon-pencil')); ?>
                                                <?php echo $this->Html->link('Delete', array('action' => 'delete', '?' => array_merge($_queries, array('keys' => array($user['User']['id'])))), array('title' => __d('system', 'Delete this item'), 'class' => 'ui-icon ui-icon-trash'), __d('system', 'Are you sure to delete #%s ?', $user['User']['id'])); ?>

                                                <?php echo $this->Html->link('Move up', array('action' => 'move', $user['User']['id'], 'up', '?' => $_queries), array('title' => __d('system', 'Move up this item'), 'class' => 'ui-icon ui-icon-arrowthick-1-n')); ?>
                                                <?php echo $this->Html->link('Move down', array('action' => 'move', $user['User']['id'], 'down', '?' => $_queries), array('title' => __d('system', 'Move down this item'), 'class' => 'ui-icon ui-icon-arrowthick-1-s')); ?>
                                                <?php
                                                if ($_toParent) {
                                                    echo $this->Html->link('Children', array('ext' => false, '?' => array_merge($this->request->query, array('_parent_id' => $user['User']['id']))), array('title' => __d('system', 'Management children of this item'), 'class' => 'ui-icon ui-icon-folder-collapsed'));
                                                }
                                                ?>

                                            </div>
                                        </td> 
                                    </tr>
                                    <?php $_row++; ?>
                                <?php endforeach; ?>
                            </tbody>
                        </table>
                    </div>
                </div>
                <div class="table-toolbar ui-corner-bottom clearfix">
                    <div class="table-info">
                        <?php echo $this->Paginator->counter(__d('system', 'Showing %start% to %end% of %count% entries')); ?>
                    </div>
                    <div class="table-paginate clearfix">
                        <?php echo $this->Paginator->first(__d('system', 'Fisrt')); ?>
                        <?php echo $this->Paginator->prev(__d('system', 'Prev'), array(), null, array('class' => 'disabled')); ?>
                        <?php echo $this->Paginator->numbers(array('separator' => '')); ?>
                        <?php //echo $this->Paginator->numbers(array('separator' => '', 'ellipsis' => '<span>...</span>', 'first' => 2, 'last' => 2)); ?>
                        <?php echo $this->Paginator->next(__d('system', 'Next'), array(), null, array('class' => 'disabled')); ?>
                        <?php echo $this->Paginator->last(__d('system', 'Last')); ?>
                    </div>
                </div>
            </div>
            <?php
            echo $this->Form->hidden('task', array('id' => 'task', 'value' => ''));
            echo $this->Form->end();
            ?>
        </div>
        <!-- /Table -->
    </div>
</div>